// pages/createevent/createevent.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    eventname:"",
    eventdetail:"",
    evnts:[ {_id: "oaCiw5aMKqMePlOALcStzFk0YnSY", name: "test", detail: "test2"}
    ,{_id: "oaCiw5UvRKjTINY_8hCrjNcRZUWI", name: "fewf", detail: "ddddd"}]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    const evnts = await getApp().call({
      name:"getEvents",
      data:{}
    })
    this.setData({
      evnts: evnts.data
    })
    console.log(evnts)
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onbackevent(e){
    wx.navigateBack({
      delta: 0,
    })
  },
  async onsubmit(e){
    console.log("eventname:" + this.data.eventname)
    const result = await getApp().call({ // 发起云函数，提交信息
      name: 'addEvent',
      data: {
        name: this.data.eventname,
        detail: this.data.eventdetail
      }
    })
    if(!result){
      wx.showToast({
        title: '未知错误',
        duration: 0,
        icon: icon,
        image: 'image',
        mask: true,
        success: (res) => {},
        fail: (res) => {},
        complete: (res) => {
        },
      })
    }
    else{
      wx.navigateBack({
        delta: 0,
      })
    }
  },
})